<?php

namespace app\adminapi\controller\room;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\room\department\DepartmentLists;
use app\adminapi\logic\room\department\DepartmentLogic;
use app\adminapi\validate\room\department\DepartmentValidate;
use app\adminapi\validate\room\RoomDepartmentValidate;
use app\common\enum\DefaultEnum;
use app\common\model\Building;
use app\common\model\Campus;

/**
 * 科室管理控制器
 * Class RoomDepartmentController
 * @package app\adminapi\controller\room
 */
class DepartmentController extends BaseAdminController
{


    /**
     * @notes 获取科室管理列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function lists()
    {
        return $this->dataLists(new DepartmentLists());
    }


    /**
     * @notes 添加科室管理
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function add()
    {
        $params = (new DepartmentValidate())->post()->goCheck('add');
        $result = DepartmentLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(DepartmentLogic::getError());
    }


    /**
     * @notes 编辑科室管理
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function edit()
    {
        $params = (new DepartmentValidate())->post()->goCheck('edit');
        $result = DepartmentLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(DepartmentLogic::getError());
    }


    /**
     * @notes 删除科室管理
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function delete()
    {
        $params = (new DepartmentValidate())->post()->goCheck('delete');
        DepartmentLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取科室管理详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function detail()
    {
        $params = (new DepartmentValidate())->goCheck('detail');
        $result = DepartmentLogic::detail($params);
        return $this->data($result);
    }


    /**
     * 编辑科室状态
     *
     * @return void
     */
    public function updateStatus(){
        $params = input();
        $result = DepartmentLogic::updateStatus($params);
        if (true === $result) {
            return $this->success('修改成功', [], 1, 1);
        }
        return $this->fail(DepartmentLogic::getError());
    }

    public function campusAll(){
        $list = Campus::where('status',DefaultEnum::SHOW)->field('id,name')->select()->toArray();
        return $this->data($list);
    }

 
}